package jdbc;

import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectionFactory {
	
	public static Connection connection = null;
	
	public static synchronized Connection getConnection() throws SQLException {
		try {
			//Class.forName(JDBCProperties.driver);
			Driver driver;
			try {
				driver = (Driver)Class.forName(JDBCProperties.driver).newInstance();
			} catch (InstantiationException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/floapp",JDBCProperties.login,JDBCProperties.senha);
		System.out.println("Conectado ao banco...");
		return connection;
	}
	
	public static synchronized void closeConnection() {
		try {
			connection.close();
			System.out.println("Conexao fechada...");
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}